﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BusinessLayer;

namespace WebApplication.Controllers
{
    [Authorize]
    public class CarStatesController : ApiController
    {
        public List<Dictionary<string, object>> GetCarStates(int id)
        {
            List<Dictionary<string, object>> carStates = new List<Dictionary<string, object>>();
            Dictionary<string, object> carState;

            Reader<CarState> reader = CarState.Repository.ReadAll(id);
            while (reader.Read())
            {
                carState = new Dictionary<string, object>();
                carState["x"] = reader.Current.Location.X;
                carState["y"] = reader.Current.Location.Y;
                carState["directionSin"] = Math.Sin(reader.Current.Direction);
                carState["directionCos"] = Math.Cos(reader.Current.Direction);
                carState["speed"] = reader.Current.Speed;
                carState["oilPressure"] = reader.Current.OilPressure;
                carState["gasPressure"] = reader.Current.GasPressure;
                carState["time"] = reader.Current.Time;

                carStates.Add(carState);
            }
            reader.Close();

            return carStates;
        }
    }
}
